<template>
	<view class="coupon-center-page">
		<!-- 自定义导航栏 -->
		<view class="nav-bar" :style="{ paddingTop: statusBarHeight + 'px' }">
			<view class="nav-content">
				<view class="nav-back" @click="goBack">
					<text class="back-icon">‹</text>
				</view>
				<text class="nav-title">领券中心</text>
				<view class="nav-right">
					<text class="nav-icon">⋯</text>
					<text class="nav-icon">|</text>
					<text class="nav-icon">○</text>
				</view>
			</view>
		</view>

		<!-- 内容区域 -->
		<view class="content-area">
			<view 
				class="coupon-card" 
				v-for="(item, index) in couponList" 
				:key="index"
			>
				<!-- 左侧优惠券样式区域 -->
				<view class="coupon-left">
					<view class="coupon-value">
						<text class="currency">¥</text>
						<text class="amount">{{ item.amount }}</text>
					</view>
				</view>
				
				<!-- 右侧信息区域 -->
				<view class="coupon-right">
					<view class="coupon-info">
						<text class="condition">{{ item.condition }}</text>
						<text class="limit">{{ item.limit }}</text>
						<text class="validity">有效期: {{ item.validity }}</text>
					</view>
					<button 
						class="claim-btn" 
						:class="{ claimed: item.isClaimed }"
						:disabled="item.isClaimed"
						@click="claimCoupon(index)"
					>
						{{ item.isClaimed ? '已领取' : '领取' }}
					</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		ref
	} from 'vue';

	// 状态栏高度
	const statusBarHeight = ref(0);

	// 优惠券列表数据
	const couponList = ref([
		{
			amount: 20,
			condition: '满200元可用',
			limit: '仅限于XX加油站使用',
			validity: '2020.04.11—2023.05.11',
			isClaimed: false
		},
		{
			amount: 20,
			condition: '满200元可用',
			limit: '仅限于XX加油站使用',
			validity: '2020.04.11—2023.05.11',
			isClaimed: true
		},
		{
			amount: 50,
			condition: '满500元可用',
			limit: '仅限于XX洗车店使用',
			validity: '2023.06.01—2023.12.31',
			isClaimed: false
		},
		{
			amount: 30,
			condition: '满300元可用',
			limit: '仅限于XX维修店使用',
			validity: '2023.07.01—2023.12.31',
			isClaimed: false
		}
	]);

	// 返回上一页
	const goBack = () => {
		uni.navigateBack();
	};

	// 领取优惠券
	const claimCoupon = (index) => {
		if (couponList.value[index].isClaimed) {
			return;
		}
		
		// 这里可以调用后端API领取优惠券
		couponList.value[index].isClaimed = true;
		uni.showToast({
			title: '领取成功',
			icon: 'success'
		});
	};

	onLoad(() => {
		// 获取状态栏高度
		const systemInfo = uni.getSystemInfoSync();
		statusBarHeight.value = systemInfo.statusBarHeight;
	});
</script>

<style scoped>
	.coupon-center-page {
		background-color: #f5f5f5;
		min-height: 100vh;
	}

	/* 导航栏 */
	.nav-bar {
		background-color: #007AFF;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 1000;
	}

	.nav-content {
		height: 44px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
	}

	.nav-back {
		width: 60rpx;
		height: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.back-icon {
		color: #fff;
		font-size: 48rpx;
		font-weight: 300;
		line-height: 1;
	}

	.nav-title {
		color: #fff;
		font-size: 36rpx;
		font-weight: 500;
		flex: 1;
		text-align: center;
	}

	.nav-right {
		display: flex;
		align-items: center;
		gap: 10rpx;
	}

	.nav-icon {
		color: #fff;
		font-size: 32rpx;
		line-height: 1;
	}

	/* 内容区域 */
	.content-area {
		margin-top: calc(44px + var(--status-bar-height, 0px));
		padding: 30rpx;
		background-color: #f5f5f5;
		min-height: calc(100vh - 44px - var(--status-bar-height, 0px));
	}

	/* 优惠券卡片 */
	.coupon-card {
		display: flex;
		background-color: #fffef7;
		border-radius: 16rpx;
		overflow: visible;
		margin-bottom: 30rpx;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
		min-height: 200rpx;
		position: relative;
	}

	/* 左侧优惠券样式区域 */
	.coupon-left {
		width: 200rpx;
		background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
		position: relative;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-shrink: 0;
		border-radius: 16rpx 0 0 16rpx;
	}

	/* 优惠券左侧的圆形缺口效果 */
	.coupon-left::before {
		content: '';
		position: absolute;
		top: -20rpx;
		right: -20rpx;
		width: 40rpx;
		height: 40rpx;
		background-color: #f5f5f5;
		border-radius: 50%;
		z-index: 2;
		box-shadow: 0 0 0 2rpx #fffef7;
	}

	.coupon-left::after {
		content: '';
		position: absolute;
		bottom: -20rpx;
		right: -20rpx;
		width: 40rpx;
		height: 40rpx;
		background-color: #f5f5f5;
		border-radius: 50%;
		z-index: 2;
		box-shadow: 0 0 0 2rpx #fffef7;
	}

	.coupon-value {
		display: flex;
		align-items: baseline;
		color: #fff;
	}

	.currency {
		font-size: 32rpx;
		font-weight: 500;
	}

	.amount {
		font-size: 72rpx;
		font-weight: bold;
		line-height: 1;
	}

	/* 右侧信息区域 */
	.coupon-right {
		flex: 1;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		background-color: #fffef7;
		position: relative;
		border-radius: 0 16rpx 16rpx 0;
	}

	.coupon-info {
		display: flex;
		flex-direction: column;
		gap: 12rpx;
		flex: 1;
	}

	.condition {
		font-size: 32rpx;
		color: #ff6b35;
		font-weight: 500;
	}

	.limit {
		font-size: 28rpx;
		color: #999;
	}

	.validity {
		font-size: 28rpx;
		color: #999;
	}

	/* 领取按钮 */
	.claim-btn {
		align-self: flex-end;
		width: 140rpx;
		height: 60rpx;
		line-height: 60rpx;
		background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
		color: #fff;
		border: none;
		border-radius: 30rpx;
		font-size: 28rpx;
		font-weight: 500;
		padding: 0;
		margin-top: 20rpx;
		box-sizing: border-box;
	}

	.claim-btn.claimed {
		background-color: #e0e0e0;
		color: #999;
		background: #e0e0e0;
	}

	.claim-btn:disabled {
		background-color: #e0e0e0;
		color: #999;
		background: #e0e0e0;
	}
</style>
